home *** CD-ROM | disk | FTP | other *** search
- using System;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Web;
- using System.Web.UI;
- using System.Drawing;
-
- namespace gbweb
- {
- /// <summary>
- /// Summary description for Search.
- /// </summary>
- public partial class Photo : Page
- {
-
- protected void Page_Load(object sender, EventArgs e)
- {
- //Intialize a cookie variable
- HttpCookie cookie;
-
- //If this is the first time coming to the photo page
- if (!IsPostBack)
- {
- //If the querystring contains a parm of pic convert it to a string and set the url of the image control
- if (Request.Params["pic"] != null)
- {
- picture.ImageUrl = Convert.ToString(Request.Params["pic"]);
- }
- else
- {
- //Since the querystring did not contain a pic parm we want to hide the image size and rotation
- //radio buttons
- photoDiv.Visible = false;
- return;
- }
- //Get the saved coode for the default size of the photo.....this is remembered from session to session
- cookie = Request.Cookies["photoSize"];
- photo_Size.SelectedValue = cookie != null ? cookie.Value : "2";
-
- //Make the image size and rotation radio buttons visible
- photoDiv.Visible = true;
- }
-
- //If the image control has its url location set we need to set it to the way the user wants it to display
- if (picture.ImageUrl != null)
- {
- //To ensure that each display of the picture is accurate we need to reset the url of the image control
- //to the original value......this is becuase the image url is changed if the user chooses to rotate the image.
- picture.ImageUrl = Convert.ToString(Request.Params["pic"]);
-
- //Split the image url into the page and the actual query string
- string[] Sfile = picture.ImageUrl.Split('?');
-
- //Deserialize the querystring which is the file path and filename
- string Dfile = (string)PublicDownload.Deseralize(Sfile[1]);
-
- //Create an image from the file location
- Image image = Image.FromFile(Dfile);
-
- //Get pull the filename from the picture path to be displayed to the user
- string photoinfo = Path.GetFileName(Dfile);
-
- //Pull the image dimensions from the image to be displayed to the user
- photoinfo += " - Actual Size: " + image.Width + "x" + image.Height;
-
- //Set the info lable to the value of the filename of the image and the image dimensions
- photoInfo.Text = photoinfo;
-
- //Set the image display size
- switch (Convert.ToInt32(photo_Size.SelectedValue))
- {
- case 0:
- {
- picture.Height = image.Height;
- picture.Width = image.Width;
- break;
- }
- case 1:
- {
- picture.Height = Convert.ToInt32(image.Height * .75);
- picture.Width = Convert.ToInt32(image.Width * .75);
- break;
- }
- case 2:
- {
- picture.Height = Convert.ToInt32(image.Height * .50);
- picture.Width = Convert.ToInt32(image.Width * .50);
- break;
- }
- case 3:
- {
- picture.Height = Convert.ToInt32(image.Height * .25);
- picture.Width = Convert.ToInt32(image.Width * .25);
- break;
- }
- case 4:
- {
- picture.Height = Convert.ToInt32(image.Height * .10);
- picture.Width = Convert.ToInt32(image.Width * .10);
- break;
- }
- default:
- {
- picture.Height = Convert.ToInt32(image.Height * .50);
- picture.Width = Convert.ToInt32(image.Width * .50);
- break;
- }
- }
-
- //If the user has choosen to rotate the image then we need to process the image and reset the image sizeing
- //to work with the rotation option
- if (photo_Rotation.SelectedValue != "0")
- {
- //We must set the url of the rotated image to call download.ashx so that it can be streamed back to the image control
- picture.ImageUrl = Download.GetDownloadUrl(false, true, Download.InternalFiles.ModifiedPhoto, PublicDownload.Serialize(Dfile + "~" + picture.Height.Value + "~" + picture.Width.Value + "~" + photo_Rotation.SelectedValue));
- //Depending on the rotation option the height and width of the image control need to be swapped.
- switch (photo_Rotation.SelectedValue)
- {
- case "1":
- {
- double H = picture.Height.Value;
- double W = picture.Width.Value;
- picture.Height = Convert.ToInt32(W);
- picture.Width = Convert.ToInt32(H);
- break;
- }
- case "3":
- {
- double H = picture.Height.Value;
- double W = picture.Width.Value;
- picture.Height = Convert.ToInt32(W);
- picture.Width = Convert.ToInt32(H);
- break;
- }
- }
- }
- //Cleanup
- image.Dispose();
- }
-
- //Store the selected sort order in the cookie for the next image display
- cookie = new HttpCookie("photoSize", photo_Size.SelectedValue);
- cookie.Expires = DateTime.Now.AddYears(1);
- Response.Cookies.Add(cookie);
-
- }
-
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP.NET Web Form Designer.
- //
- InitializeComponent();
- base.OnInit(e);
- }
-
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
-
- }
- #endregion
- }
- }
-